package me.xplabs.scene 
{
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import me.xplabs.Globals;
	import me.xplabs.constant.SceneType;
	import me.xplabs.interfaces.IScene;
	import me.xplabs.msg.NotificationName;
	import me.xplabs.ui.baseui.Button;
	import me.xplabs.ui.UICompent;
	import me.xplabs.utils.Utils;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author xiaohan
	 */
	public class StartSceneMediator extends Mediator implements IScene 
	{
		public static const NAME:String = "StartSceneMediator";
		private var _container:Sprite;
		private var _isInit:Boolean;
		
		private var _backGround:Bitmap;
		private var _titleMark:Bitmap;
		private var _startBtn:Button;
		
		private var _startAnimation:StartAnimation;
		public function StartSceneMediator( viewComponent:Object=null) 
		{
			super(NAME, viewComponent);
		}
		private function init():void 
		{
			if (_isInit) return;
			_isInit = true;
			_container = new Sprite();
			
			_backGround = new Bitmap(Globals.lib.getResObj(Globals.domain.texture + 2));
			_titleMark = new Bitmap(Globals.lib.getResObj(Globals.domain.texture + 9));
			_titleMark.x = Globals.centerW - _titleMark.width * .5;
			_titleMark.y = 30;
			
			_startBtn = Globals.ui.button("", 1);
			//_startBtn.x = Globals.centerW - _startBtn.width * .5;
			//_startBtn.y = 400;
			_startBtn.x = 267;
			_startBtn.y = 312;
			_startBtn.callback = clickStartHandler;
			//UICompent.addListener(_startBtn);
			
			_startAnimation = new StartAnimation();
			_startAnimation.x = Globals.centerW;
			_startAnimation.y = Globals.centerH;
			_startAnimation.addEventListener("playOver", startAnimationPlayOverHandler);
			
		}
		
		private function startAnimationPlayOverHandler(e:Event):void 
		{
			_container.addChild(_backGround);
			//_container.addChild(_titleMark);
			_container.addChild(_startBtn);
		}
		
		private function clickStartHandler(e:MouseEvent):void 
		{
			//sendNotification(NotificationName.CHANGE_SCENE, SceneType.GAME_SCENE);
			sendNotification(NotificationName.CHANGE_SCENE, SceneType.SELECT_SCENE);
		}
		public function show():void 
		{
			init();
			print("显示开始视图");
			DisplayObjectContainer(viewComponent).addChild(_container);
			
			//_container.addChild(_backGround);
			_container.addChild(_startAnimation);
			_startAnimation.gotoAndPlay(2);
			
		}
		
		public function dispose():void 
		{
			print("销毁开始视图");
			if (DisplayObjectContainer(viewComponent).contains(_container)) 
				DisplayObjectContainer(viewComponent).removeChild(_container);
		}
		
		public function get container():Sprite 
		{
			return _container;
		}
	}

}